package com.fmy.mcsecurity.token.impl;

import cn.hutool.core.lang.UUID;
import com.fmy.mcsecurity.token.TokenGenerate;
import com.fmy.mcsecurity.token.model.SecurityToken;
import org.springframework.security.core.Authentication;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @author Mr.fmy
 * @version 1.0.0
 * @ClassName UidTokenGenerate
 * @Description TODO UUIDtoken生成实现
 * @createTime 2020/4/24 09:51
 */
public class UidTokenGenerate implements TokenGenerate {

    @Override
    public SecurityToken generate(String client, String type, Authentication authentication) {
        return new SecurityToken().setToken(UUID.randomUUID().toString())
                .setRefreshToken(UUID.randomUUID().toString())
                .setTokenExpire(getTokenExp()).setRefreshTokenExpire(getRefresExp())
                .setLoginTime(LocalDateTime.now())
                .setTimeUnit(getTimeUnit());
    }

    @Override
    public long getTokenExp() {
        return 7L;
    }

    @Override
    public long getRefresExp() {
        return 14L;
    }

    @Override
    public TimeUnit getTimeUnit() {
        return TimeUnit.DAYS;
    }
}
